package com.gin.no_gay_alliance.param;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * 道具参数
 *
 * @author : ginstone
 * @version : v1.0.0
 * @since : 2023/9/8 15:26
 **/
public class ItemParam implements Parcelable {
    public static final Creator<ItemParam> CREATOR = new Creator<ItemParam>() {
        @Override
        public ItemParam createFromParcel(Parcel in) {
            return new ItemParam(in);
        }

        @Override
        public ItemParam[] newArray(int size) {
            return new ItemParam[size];
        }
    };
    /**
     * 对人道具的目标
     */
    public Long userId;
    /**
     * 对贴道具的目标参数，主题id
     */
    public Long topicId;
    /**
     * 对贴道具的目标参数，回复id
     */
    public Long replyId;

    public ItemParam() {
    }

    public ItemParam(Long userId) {
        this.userId = userId;
    }

    public ItemParam(Long topicId, Long replyId) {
        this.topicId = topicId;
        this.replyId = replyId;
    }

    protected ItemParam(Parcel in) {
        if (in.readByte() == 0) {
            userId = null;
        } else {
            userId = in.readLong();
        }
        if (in.readByte() == 0) {
            topicId = null;
        } else {
            topicId = in.readLong();
        }
        if (in.readByte() == 0) {
            replyId = null;
        } else {
            replyId = in.readLong();
        }
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        if (userId == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeLong(userId);
        }
        if (topicId == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeLong(topicId);
        }
        if (replyId == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeLong(replyId);
        }
    }

    public boolean isToReply() {
        return topicId != null && replyId != null;
    }

    public boolean isToUser() {
        return userId != null;
    }
}
